<?php
class Like extends CI_Controller {
	
	public function __construct() {
		parent::__construct ();
		$this->load->model('like_model');
		$this->load->model('feed_model');
		$this->load->model('user_model');
		$this->load->model('notification_model');
	}
	
	public function index(){
		$uid = $this->session->userdata('user_id');
		if ($uid){
			$pid = $this->input->post('pid');
			$this->_send_like_notification($uid, $pid);
			echo $this->like_model->like($uid,$pid);
		} else {
			echo -1;;
			
		}
	}
	
	function _send_like_notification($uid,$pid){
		//FIXME 自己的喜欢不显示
		
		$feed = $this->feed_model->get($pid);
		$user = $this->user_model->get_user($uid);
		global $type_map;
		if ($feed&&$user) {
			$this->notification_model->add(
					$feed['author'],
					$user['uname'].'赞了您'.$type_map[$feed['type']],
					base_url('index.php/blog/index/'.$feed['bid'].'#f'.$pid)
				);
		}
	}
}

?>